package com.mys.dxc;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;


public class TestDataPool implements Runnable {

	public static long date1 = 0;
	public static int count = 0;
	
	
	public static void main(String[] args) {
		
		if (date1 == 0) {
			date1 = System.currentTimeMillis();
			System.out.println(date1);
		}
		ExecutorService executor = Executors.newFixedThreadPool(2);
		Runnable r = new TestDataPool();
		executor.execute(r);
		executor.shutdown();
//		for (int i = 0; i < 100; i++)
//		{
//			
//			Thread thread = new Thread(r);
//			thread.start();
//		}
	}

	@Override
	public void run() {
		
		
		for (int i = 0; i < 100; i++) {
			try {
				Connection conn = mydatasource.getConnection();
				if (conn != null) {
					Statement statement = conn.createStatement();
					ResultSet rs = statement.executeQuery("select * from traceip");
					while (rs.next()) {
						String username = rs.getString(3);
						System.out.println(Thread.currentThread().getName()+":"+username);
					}
					rs.close();
					statement.close();
					conn.close();
				}
			} catch (SQLException e) {
				e.printStackTrace();
			} catch (Exception e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		//count++;
		//if (count == 100) {
			long date2 = System.currentTimeMillis();
			System.out.println(date2);
			System.out.println("运行完毕!耗时为：" + (date2 - date1) + "ms");
		//}
	}

}
